import getInfo from "@/pages/noticeApp/utils/getInfo";
import { getStorage, MyStorage } from "../pages/components/utils";
import MyUtils from "../pages/noticeApp/components/personal/utils";

const getEnv = () => {
  return MyUtils.getStorage("env") || MyUtils.getQueryVariable("env");
};

//全局子系统默认路径
let BASE_URL = "";
let BASE_SOCKET_URL = "";
export const getBaseUrl = () => {
  // if (process.env.NODE_ENV === "development") {
  //       //开发环境 - 根据请求不同返回不同的BASE_URL
  //       BASE_URL = 'http://192.168.129.203:7779';
  //    BASE_SOCKET_URL = ""
  // }
  if (process.env.TARO_ENV === "h5") {
    if (getEnv() === "weapp") {
      if (process.env.NODE_ENV === "development") {
        let url = MyUtils.getStorage("baseUrl220");
        BASE_URL = url;
      } else {
        let url = MyUtils.getStorage("baseUrl220");
        BASE_URL = url;
      }
    } else {
      if (process.env.NODE_ENV === "development") {
        // BASE_URL = 'https://xdtest.aiedu100.com/notice'//124环境
        BASE_URL = 'https://jdtest.aiedu100.com/edu-office-platform' //jd
        // BASE_URL = 'http://isca.lancooedu.com/notice'//云端
        // BASE_URL = 'http://iscb.lancooedu.com/notice'//云端
        // BASE_URL='http://36.139.124.81:10000/notice/' //日照
        // BASE_URL='http://jw.llzx.com/notice/' //亮亮中学
        // BASE_URL = 'http://120.196.79.139:22101/notice'//124环境的外网映射
        // BASE_URL='http://192.168.122.200:33101/notice' //中职
        // BASE_URL = 'http://120.236.115.246:22329/notice/' //124映射
        // BASE_URL = 'http://192.168.122.124:22101/notice/'//124环境
        // BASE_URL = 'http://192.168.129.115:10329/notice/'//129.1环境
        // BASE_URL = 'http://192.168.122.120:42329/notice/' //122.120
        // BASE_URL = "http://www.xhwlxx.com:10106/notice/";
        // BASE_URL='https://zijinmiddleschool.zjky.cn:10102/notice/'
        // BASE_URL = 'http://xyt.zhuoyuezhongxue.com:10329/notice/'//石家庄卓越中学
        // BASE_URL = 'https://zhxy.sttbzx.com:9801/notice/'//石家庄卓越中学
        // BASE_URL = 'http://www.mczjjt.com:8080/notice/'//石家庄卓越中学
      } else {
        BASE_URL = "/edu-office-platform";
      }
    }
  } else {
    if (process.env.NODE_ENV === "development") {
      let url = MyUtils.getStorage("baseUrl220");
      BASE_URL = url;
    } else {
      let url = MyUtils.getStorage("baseUrl220");
      BASE_URL = url;
    }
  }
  // console.log(BASE_URL,'系统地址')
  return BASE_URL;
};

export const setBaseUrl = (newBaseUrl) => {
  BASE_URL = newBaseUrl;
};

//socket地址
export const getBaseSocketUrl = () => {
  return BASE_SOCKET_URL;
};

export const setBaseSocketUrl = (newBaseSocketUrl) => {
  BASE_SOCKET_URL = newBaseSocketUrl;
};

// 获取基础平台地址
export const getBasePlatformUrl = () => {
  const storage: MyStorage = getStorage();
  return storage.get("basePlatformUrl");
};

// 获取门户地址
export const getPortalmUrl = () => {
  const storage: MyStorage = getStorage();
  const portalUrl = storage.get("portalUrl");
  if (!portalUrl) return "";
  if (portalUrl.substring(portalUrl.length - 1) == "/") {
    return portalUrl.substring(0, portalUrl.length - 1);
  }
  return portalUrl;
};

//校园通根路径
export const API_CampusRoot = "https://campus.lancooedu.com";
//代理路径
export const API_TransmitUrl = () => {
  let transimitUrl: string;
  switch (process.env.NODE_ENV) {
    case "development":
      transimitUrl = "https://campus.lancooedu.com:50000";
      break; //http://192.168.129.172:50000
    case "production":
      transimitUrl = "https://campus.lancooedu.com:50000";
      break;
    default:
      transimitUrl = "https://campus.lancooedu.com:50000";
      break;
  }
  return transimitUrl;
};
